package com.Data;

import java.io.Serializable;
import java.util.LinkedList;

import android.content.Context;

public class Account implements Serializable, Storable {
	private static final long serialVersionUID = 288718907871515399L;
	
	private String nickname;
	private LinkedList<Character> chars;
	private int selectedCharIndex;
	private int clearStage;
	private int score;
	
	public Account(Context context) {
		nickname = "new_acount";
		chars = new LinkedList<Character>();
		for (int i=0; i<5; i++) {
			chars.add(new Character(context.getResources(), i));
		}
		selectedCharIndex = 0;
		clearStage = 0;
		score = 0;
	}
	
	public boolean save(int slotNum) {
		for (int i = 0; i < chars.size(); i++) {
			chars.get(i).setAngryGauge(0);
		}
		return FileManager.save(slotNum, this, FileManager.ACCOUNT);
	}
	
	public boolean load(int slotNum) {
		return FileManager.load(slotNum, this, FileManager.ACCOUNT);
	}

	@Override
	public void setData(Storable data) {
		Account account = (Account)data;
		
		this.nickname = account.nickname;
		for (int i = 0; i < chars.size(); i++) chars.get(i).setData(account.getChars().get(i));
		this.selectedCharIndex = account.selectedCharIndex;
		this.clearStage = account.clearStage;
		this.score = account.score;
	}
	
	public boolean isAllClear() {
		if(clearStage >= 40)	return true;
		return false;
	}

	public String getNickname() {	return nickname;	}
	public void setNickname(String nickname) {	if(nickname != null)	this.nickname = nickname;	}
	public LinkedList<Character> getChars() {	return chars;	}
	public Character getSelectedChar() {	return chars.get(selectedCharIndex);	}
	public int getScore() {	return score;	}
	public void setScore(int score) {	this.score = score;	}
	public void plusScore(int plusScore)	{	this.score += plusScore;	}
	public int getSelectedCharIndex() {	return selectedCharIndex;	}
	public void setSelectedCharIndex(int selectedCharIndex) {
		if(chars.get(selectedCharIndex).isDoHave() == true)
			this.selectedCharIndex = selectedCharIndex;
	}
	public int getClearStage() {	return clearStage;	}
	public void setClearStage(int clearStage) {	this.clearStage = clearStage;	}
}
